package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.LabSupplierAppraise;
import com.ysd.lis.mapper.lab.LabSupplierAppraiseMapper;
import com.ysd.lis.request.lab.SupplierAppraiseDto;
import com.ysd.lis.request.lab.SupplierAppraiseParam;
import com.ysd.lis.service.lab.LabSupplierAppraiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-02-03
 */
@Service
public class LabSupplierAppraiseServiceImpl extends ServiceImpl<LabSupplierAppraiseMapper, LabSupplierAppraise> implements LabSupplierAppraiseService {
    @Autowired
    LabSupplierAppraiseMapper labSupplierAppraiseMapper;

    @Override
    public Result findSupplierAppraiseList(SupplierAppraiseParam param) {
        MPJLambdaWrapper<LabSupplierAppraise> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(LabSupplierAppraise.class);
        if (StringUtils.isNotBlank(param.getSupplierId())) {
            queryWrapper.eq(LabSupplierAppraise::getSupplierId,param.getSupplierId());
        }

        queryWrapper.eq(LabSupplierAppraise::getDelFlag, 0)
                .orderByAsc(LabSupplierAppraise::getSeq);
        return Result.succ(1, "查询成功", labSupplierAppraiseMapper.selectList(queryWrapper));
    }

    @Override
    public Result saveOrUpdateSupplierAppraise(SupplierAppraiseDto dto) {
        List<LabSupplierAppraise> appraiseList = dto.getAppraiseList();
        boolean b = this.saveOrUpdateBatch(appraiseList);
        if(b){
            return Result.succ(1, "成功", null);
        }else {
            return Result.fail(400,"失败","");
        }
    }
    @Override
    public Result batchDeleteSupplierAppraiseList(SupplierAppraiseDto dto) {
        List<LabSupplierAppraise> appraiseList = dto.getAppraiseList();
        List<String> ids = appraiseList.stream().map(LabSupplierAppraise::getId).collect(Collectors.toList());
        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }
}
